import {makeAutoObservable} from 'mobx'

class TaskStore {
    list = [{
        id: 1, name: '学习react', isDone: true
    }, {
        id: 2, name: '搞定mobx', isDone: false
    }]

    constructor() {
        makeAutoObservable(this)
    }

    singleCheck(id, isDone) {
        const item = this.list.find(item => item.id === id)
        item.isDone = isDone
    }

    allCheck(checked) {
        this.list.forEach(n => {
            n.isDone = checked
        })
    }

    get isAll() {
        return this.list.every(n => n.isDone)
    }

    delTask = (id) => {
        this.list = this.list.filter(n => n.id !== id)
    }

    addTask = (task) => {
        this.list.push(task)
    }
}

export default TaskStore
